package Pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WebDriver;

public class VersionPage {
    
   
    public WebElement ver, ver_modif, usag;    
    private String cl, cs, xpa;           
    public String version, version_modifier, useragent;      
        
    
    public WebElement getVersion(WebDriver driver) throws Exception {
        
         cl = "version";
         cs = "#version > span:nth-child(1)";
         xpa = "//*[@id=\"version\"]/span[1]";
         
        
        try {
            try {
                ver = (driver.findElement(By.className(cl)));
            } catch (Exception e1) {
                try {
                    ver = driver.findElement(By.cssSelector(cs));
                } catch (Exception e2) {
                    ver = driver.findElement(By.xpath(xpa));
                }
            }                                    
            version = ver.getText();           
        } catch (Exception e) {
            System.out.println("ERROR: " + e.getMessage());
        }
        
        System.out.println("Browser version: " + version);
        return ver;
    }
    
    public WebElement getBuildType(WebDriver driver) throws Exception {
        cl = "version";
        cs = "#version > span:nth-child(4)";
        xpa = "//*[@id=\"version\"]/span[4]";
         
        
        try {
            try {
                ver_modif = (driver.findElement(By.className(cl)));
            } catch (Exception e1) {
                try {
                    ver_modif = driver.findElement(By.cssSelector(cs));
                } catch (Exception e2) {
                    ver_modif = driver.findElement(By.xpath(xpa));
                }
            }                                                
            version_modifier = ver_modif.getText();
        } catch (Exception e) {
            System.out.println("ERROR: " + e.getMessage());
        }
        System.out.println("Browser build version: " + version_modifier);
        return ver_modif;
    }
        
    

    public WebElement getUserAgent(WebDriver driver) throws Exception {
        cl = "";
        cs = "";
        xpa = "//*[@id=\"useragent\"]/text()";
        
        try {
            try {
                usag = (driver.findElement(By.className(cl)));
            } catch (Exception e1) {
                try {
                    usag = driver.findElement(By.cssSelector(cs));
                } catch (Exception e2) {
                    usag = driver.findElement(By.xpath(xpa));
                }
            } 
           useragent = usag.getText();           
        } catch (Exception e) {
            System.out.println("ERROR: " + e.getMessage());
        }        
        System.out.println("User agent: " + useragent);
        return usag;
    }
           

}
